package com.yiidata.rpc.grpc;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.ManagedChannelProvider;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.NettyChannelProvider;

import java.io.IOException;

/**
 * <pre>
 *
 * Created by zhenqin.
 * User: zhenqin
 * Date: 2019/4/27
 * Time: 12:37
 * Vendor: yiidata.com
 * To change this template use File | Settings | File Templates.
 *
 * </pre>
 *
 * @author zhenqin
 */
public class HelloClient {
    public static void main( String[] args ) throws IOException {
        NettyChannelBuilder channelBuilder = new NettyChannelProvider().builderForAddress("localhost", 8088);
        ManagedChannel channel = channelBuilder.usePlaintext()
                .build();
        com.yiidata.rpc.grpc.GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);

        com.yiidata.rpc.grpc.HelloRequest request = HelloRequest.newBuilder().setName("ZhenQin").build();
        HelloReply rsp = stub.sayHello(request);
        System.out.println(rsp.getMessage());

        Greeter2Grpc.Greeter2BlockingStub stub1 = Greeter2Grpc.newBlockingStub(channel);
        HelloReply message = stub1.getMessage(request);
        System.out.println(message.getMessage());
    }
}
